home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / PartMaker 4.4 / PartMaker Documents / Script Runner• / Script Runner•.rsrc / dFRK_5054 < prev    next >
Encoding:
Text File  |  1995-12-12  |  73.0 KB  |  2,459 lines

  1. /*------------------------------------------------------------------------------
  2.     File:            ScriptRunner.cpp
  3.     
  4.     Written by:        Sue Dumont        (based on SamplePart by Steve Smith)
  5.     
  6.     Copyright:        © 1995 by Apple Computer, Inc., all rights reserved.
  7.  
  8.     Description:    ScriptRunner demonstrates the functionality of a
  9.     
  10.     Demonstrates:     1. Open
  11.                      2. Part Drawing
  12.                      3. Refcounting Geometry
  13.                      4. Display Frame 'ternalization
  14.                      5. Part Init & partWrapper
  15.                      6. Persistent Reference
  16.                      7. RefCounting
  17.                      8. Storage Unit
  18.                      9. Activation
  19.                     10. Basic Event Handling
  20.                     11. Windows & Dialogs
  21.                     12. Exception Handling
  22.                     13. Memory Manager
  23.                     14. Using Resources
  24.     
  25.     Notes:        •    somThis is not set in methods where our internal data members
  26.                     are not accessed.
  27.     
  28.                 •    somInit and somUninit methods behave like C++ constructors 
  29.                     in that the inherited methods are called automatically. There
  30.                     is no need to call the parent class' somInit or somUninit. 
  31.                     (The macros are there but they do nothing and are just for
  32.                     backward compatibility). There also is no need to initialize
  33.                     instance variables to zero/NULL in somInit, since SOM guarantees
  34.                     that a newly constructed object is zeroed.
  35. ------------------------------------------------------------------------------*/
  36.  
  37. // -- Compiler/Preprocessor Notification --
  38.  
  39. #ifndef _COMPILERDEFS_
  40. #include "CompDefs.h"
  41. #endif
  42.  
  43. // -- OpenDoc Special Includes --
  44.  
  45. #ifndef _EXCEPT_
  46. #include <Except.h>
  47. #endif
  48.  
  49. // -- ScriptRunner Includes
  50.  
  51. // Notification that this is a SOM source file
  52. #define SampleCode_ScriptRunner_Class_Source
  53.  
  54. // define underscore (_) field names
  55. #define VARIABLE_MACROS
  56.  
  57. #ifndef _SCRIPTRUNNERDEF_
  58. #include "ScriptRunnerDef.h"
  59. #endif
  60.  
  61. #ifndef _SCRIPTRUNNERGLOBALS_
  62. #include "ScriptRunnerGlobals.h"
  63. #endif
  64.  
  65. #ifndef _SCRIPTRUNNERUTILS_
  66. #include "ScriptRunnerUtils.h"
  67. #endif
  68.  
  69. #ifndef SOM_SampleCode_ScriptRunner_xih
  70. #include "ScriptRunner.xih"
  71. #endif
  72.  
  73. // -- OpenDoc Includes --
  74.  
  75. #ifndef SOM_ODArbitrator_xh
  76. #include <Arbitrat.xh>
  77. #endif
  78.  
  79. #ifndef SOM_Module_OpenDoc_Commands_defined
  80. #include <CmdDefs.xh>
  81. #endif
  82.  
  83. #ifndef SOM_ODDragItemIterator_xh
  84. #include <DgItmIt.xh>
  85. #endif
  86.  
  87. #ifndef SOM_ODDraft_xh
  88. #include <Draft.xh>
  89. #endif
  90.  
  91. #ifndef SOM_ODDragAndDrop_xh
  92. #include <DragDrp.xh>
  93. #endif
  94.  
  95. #ifndef SOM_ODFacet_xh
  96. #include <Facet.xh>
  97. #endif
  98.  
  99. #ifndef SOM_ODFocusSet_xh
  100. #include <FocusSet.xh>
  101. #endif
  102.  
  103. #ifndef SOM_ODFrameFacetIterator_xh
  104. #include <FrFaItr.xh>
  105. #endif
  106.  
  107. #ifndef SOM_Module_OpenDoc_Foci_defined
  108. #include <Foci.xh>
  109. #endif
  110.  
  111. #ifndef SOM_ODSession_xh
  112. #include <ODSessn.xh>
  113. #endif
  114.  
  115. #ifndef SOM_ODShape_xh
  116. #include <Shape.xh>
  117. #endif
  118.  
  119. #ifndef SOM_ODStorageSystem_xh
  120. #include <ODStor.xh>
  121. #endif
  122.  
  123. #ifndef SOM_Module_OpenDoc_StdDefs_defined
  124. #include <StdDefs.xh>
  125. #endif
  126.  
  127. #ifndef SOM_ODTranslation_xh
  128. #include <Translt.xh>
  129. #endif
  130.  
  131. #ifndef SOM_ODTypeList_xh
  132. #include <TypeList.xh>
  133. #endif
  134.  
  135. #ifndef SOM_ODWindow_xh
  136. #include <Window.xh>
  137. #endif
  138.  
  139. #ifndef SOM_ODWindowState_xh
  140. #include <WinStat.xh>
  141. #endif
  142.  
  143. // -- OpenDoc Utilities --
  144.  
  145. #ifndef _BARRAY_
  146. #include <BArray.h>
  147. #endif
  148.  
  149. #ifndef _ODNEW_
  150. #include <ODNew.h>
  151. #endif 
  152.  
  153. #ifndef _ODUTILS_
  154. #include <ODUtils.h>
  155. #endif 
  156.  
  157. #ifndef _PLFMDEF_
  158. #include <PlfmDef.h>
  159. #endif
  160.  
  161. #ifndef _PASCLSTR_
  162. #include <PasclStr.h>
  163. #endif
  164.  
  165. #ifndef _TEMPOBJ_
  166. #include <TempObj.h>
  167. #endif
  168.  
  169. #ifndef _ITEXT_
  170. #include <IText.h>
  171. #endif
  172.  
  173. #ifndef _ISOSTR_
  174. #include <ISOStr.h>
  175. #endif
  176.  
  177. #ifndef _STDTYPIO_
  178. #include <StdTypIO.h>
  179. #endif
  180.  
  181. #ifndef _STORUTIL_
  182. #include <StorUtil.h>
  183. #endif
  184.  
  185. #ifndef _FOCUSLIB_
  186. #include <FocusLib.h>
  187. #endif
  188.  
  189. #ifndef _USERSRCM_
  190. #include <UseRsrcM.h>
  191. #endif
  192.  
  193. // -- Macintosh Includes --
  194.  
  195. #ifndef __LOWMEM__
  196. #include <LowMem.h>
  197. #endif
  198.  
  199. #ifndef __ERRORS__
  200. #include <Errors.h>
  201. #endif
  202.  
  203. #ifndef __RESOURCES__
  204. #include <Resources.h>
  205. #endif
  206.  
  207. #ifndef __DIALOGS__
  208. #include <Dialogs.h>
  209. #endif
  210.  
  211. #ifndef __WINDOWS__
  212. #include <Windows.h>
  213. #endif
  214.  
  215. #ifndef __TOOLUTILS__
  216. #include <ToolUtils.h>
  217. #endif
  218.  
  219. #ifndef __ICONS__
  220. #include <Icons.h>                // NewIconSuite, PlotIconSuite, DisposeIconSuite
  221. #endif
  222.  
  223. #ifndef __QUICKDRAW__
  224. #include <Quickdraw.h>
  225. #endif
  226.  
  227.  
  228. #pragma segment ScriptRunner
  229.  
  230. //==============================================================================
  231. // ScriptRunner
  232. //==============================================================================
  233.  
  234. //------------------------------------------------------------------------------
  235. //    Static Globals
  236. //------------------------------------------------------------------------------
  237.  
  238. static    Rect            gRecordButton            = {8,   7, 33,  42};
  239. static    Rect            gStopButton                = {8,  51, 32,  86};
  240. static    Rect            gRunButton                = {8,  95, 33, 130};
  241. static    Rect            gCompileButton            = {8, 153, 33, 188};
  242.  
  243.  
  244. //------------------------------------------------------------------------------
  245. // Method:        somInit
  246. // Origin:        SOMObject
  247. //
  248. // Description:    somInit and somUninit methods behave like C++ constructors 
  249. //                in that the inherited methods are called automatically. 
  250. //                There is no need to call the parent class' somInit or somUninit.
  251. //
  252. //                Also, instance variables need not be initialized to 0 or kODNULL
  253. //                since SOM guarantees that a newly constructed object is zeroed out.
  254. // Warnings:    You are not allowed to throw an exception from this method.
  255. //------------------------------------------------------------------------------
  256. SOM_Scope    void
  257. SOMLINK        ScriptRunner__somInit
  258.             (
  259.                 SampleCode_ScriptRunner*        somSelf
  260.             )
  261. {
  262.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","somInit");
  263.     
  264. }
  265.  
  266. //------------------------------------------------------------------------------
  267. // Method:        somUninit
  268. // Origin:        SOMObject
  269. //
  270. // Description:    This is the SOM equivalent of a C++ class destructor in this
  271. //                routine, you should clean up any class members which weren't
  272. //                taken care of in the ReleaseAll and Release methods.
  273. //
  274. // Warnings:    You are not allowed to throw an exception from this method.
  275. //------------------------------------------------------------------------------
  276. SOM_Scope    void
  277. SOMLINK        ScriptRunner__somUninit
  278.             (
  279.                 SampleCode_ScriptRunner*        somSelf
  280.             )
  281. {
  282.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","somUninit");
  283. }
  284.  
  285. //------------------------------------------------------------------------------
  286. // Method:        Release
  287. // Origin:        ODRefCountedObject
  288. //
  289. // Description:    This method is called each time an object releases the
  290. //                part. If the refcount falls to 0, the part should
  291. //                release the _fSelf part reference.
  292. //
  293. // Warning:        If the part releases any other object when the refcount falls
  294. //                to zero, it will need to override the Acquire method so that
  295. //                the object can be referenced again if the parts refcount should
  296. //                be incremented before it is deleted.
  297. //------------------------------------------------------------------------------
  298. SOM_Scope    void
  299. SOMLINK        ScriptRunner__Release
  300.             (
  301.                 SampleCode_ScriptRunner*    somSelf,
  302.                 Environment*                ev
  303.             )
  304. {
  305.     SampleCode_ScriptRunnerData *somThis = SampleCode_ScriptRunnerGetData(somSelf);
  306.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","Release");
  307.  
  308.     SOM_TRY
  309.         SampleCode_ScriptRunner_parent_ODPart_Release(somSelf, ev);
  310.  
  311.         if ( _fSelf->GetRefCount(ev) == 0 )
  312.             ODGetDraft(ev, _fSelf)->ReleasePart(ev, _fSelf);
  313.     SOM_CATCH_ALL
  314.     SOM_ENDTRY
  315. }
  316.  
  317. //------------------------------------------------------------------------------
  318. // Method:        ReleaseAll
  319. // Origin:        ODPersistentObject
  320. //
  321. // Description:    This method is called just prior to the part being
  322. //                deleted by the Draft. The part must release all
  323. //                references to all refcounted objects it has stored
  324. //                internally; not doing so, will cause an "invalid ref
  325. //                count" exception/error.
  326. //------------------------------------------------------------------------------
  327. SOM_Scope    void
  328. SOMLINK        ScriptRunner__ReleaseAll
  329.             (
  330.                 SampleCode_ScriptRunner*    somSelf,
  331.                 Environment*                ev
  332.             )
  333. {
  334.     SampleCode_ScriptRunnerData *somThis = SampleCode_ScriptRunnerGetData(somSelf);
  335.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","ReleaseAll");
  336.  
  337.     SOM_TRY
  338.         // If the last part instance using the globals is released,
  339.         // we need to NULL out the globals.
  340.         if ( --gGlobalsUsageCount == 0 )
  341.         {
  342.             // Release the script source data.
  343.             gGlobals->fOSAScripter->ReleaseScriptData();
  344.             
  345.             ODDeleteObject(gGlobals->fOSAScripter);
  346.             ODRelease(ev, gGlobals->fPaletteExtension);
  347.             ODRelease(ev, gGlobals->fTextTransferExt);
  348.         
  349.             ODDisposeHandle(gGlobals->fFloatWindowProc);
  350.             ODDisposeHandle(gGlobals->fDisabledRecButton);
  351.             
  352.             if ( gGlobals->fResultValue )
  353.                 ODDisposePtr(gGlobals->fResultValue);
  354.             
  355.             DisposeHandle(gGlobals->fPalette);
  356.         
  357.             // Delete the globals struct.
  358.             ODDeleteObject(gGlobals);
  359.         }
  360.         
  361.         SampleCode_ScriptRunner_parent_ODPart_ReleaseAll(somSelf, ev);
  362.  
  363.     SOM_CATCH_ALL            
  364.     SOM_ENDTRY
  365. }
  366.  
  367. //------------------------------------------------------------------------------
  368. // Method:        Purge
  369. // Origin:        ODObject
  370. //
  371. // Description:    This method is called when the draft runs out of memory;
  372. //                when a part is being deleted; or during the creation of
  373. //                stationery. The part should free up as much memory as possible.
  374. //------------------------------------------------------------------------------
  375. SOM_Scope    ODSize
  376. SOMLINK        ScriptRunner__Purge
  377.             (
  378.                 SampleCode_ScriptRunner*    somSelf,
  379.                 Environment*                ev,
  380.                 ODSize                        /* size */
  381.             )
  382. {
  383.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","Purge");
  384.  
  385.     return 0;
  386. }
  387.  
  388. //------------------------------------------------------------------------------
  389. // Method:        InitPart
  390. // Origin:        ODPart
  391. //
  392. // Description:    The ScriptRunnerAgent object calls the draft's CreatePart
  393. //                method, which in turn calls the InitPart method to create
  394. //                and initialize the ScriptRunner part.
  395. //------------------------------------------------------------------------------
  396. SOM_Scope    void
  397. SOMLINK        ScriptRunner__InitPart
  398.             (
  399.                 SampleCode_ScriptRunner*        somSelf,
  400.                 Environment*                    ev,
  401.                 ODStorageUnit*                    storageUnit,
  402.                 ODPart*                            partWrapper
  403.             )
  404. {
  405.     SampleCode_ScriptRunnerData *somThis = SampleCode_ScriptRunnerGetData(somSelf);
  406.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","InitPart");
  407.  
  408.     SOM_TRY
  409.         // We must call the initialize method of our parent class
  410.         // to allow OpenDoc to annotate our part's storageUnit, and
  411.         // to set our refcount.
  412.         SampleCode_ScriptRunner_parent_ODPart_InitPart(somSelf, ev, storageUnit, partWrapper);
  413.  
  414.         // To allow editor swapping (translation) at runtime, OpenDoc requires
  415.         // Store a "reference" to ourself. We'll need this when interacting with
  416.         // the OpenDoc API (ie. WindowState::RegisterWindow(), 
  417.         // Dispatcher::RegisterIdle, etc). The "partWrapper" passed to us here 
  418.         // is the "reference" OpenDoc wants us to use.
  419.         _fSelf = partWrapper;
  420.  
  421.         // NOTE: This code is present to support the Shell during stationery
  422.         // creation, which is pointless for this part.
  423.         somSelf->CheckAndAddProperties(ev, storageUnit);
  424.  
  425.         // Call the common initialization code to get set up.
  426.         somSelf->Initialize(ev, storageUnit);
  427.     SOM_CATCH_ALL
  428.     SOM_ENDTRY
  429. }
  430.  
  431. //------------------------------------------------------------------------------
  432. // Method:        InitPartFromStorage
  433. // Origin:        ODPart
  434. //
  435. // Description:    This method is called when a document/stationery is
  436. //                being opened or when the part is internalized by its
  437. //                containing part. The part should merely read in its
  438. //                saved state/content and initialize itself. The part
  439. //                 must not alter its storage unit; otherwise, the "Save"
  440. //                 menu item becomes enabled without the user actually
  441. //                having made a change to the document.
  442. //------------------------------------------------------------------------------
  443. SOM_Scope    void
  444. SOMLINK        ScriptRunner__InitPartFromStorage
  445.             (
  446.                 SampleCode_ScriptRunner*    somSelf,
  447.                 Environment*                ev,
  448.                 ODStorageUnit*                storageUnit,
  449.                 ODPart*                        partWrapper
  450.             )
  451. {
  452.     SampleCode_ScriptRunnerData *somThis = SampleCode_ScriptRunnerGetData(somSelf);
  453.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","InitPartFromStorage");
  454.     
  455.     SOM_TRY
  456.         SampleCode_ScriptRunner_parent_ODPart_InitPartFromStorage(somSelf, ev, 
  457.                                                         storageUnit, partWrapper);
  458.         _fSelf = partWrapper;
  459.         somSelf->Initialize(ev, storageUnit);
  460.     SOM_CATCH_ALL
  461.     SOM_ENDTRY
  462. }
  463.  
  464. //------------------------------------------------------------------------------
  465. // Method:        Initialize
  466. // Origin:        ScriptRunner
  467. //
  468. // Description:    This method is called during the internalization of the part
  469. //                from a document. Its purpose is to initialize all fields of
  470. //                the part and to convert ISO types to tokens for faster 
  471. //                comparisons throughout the code.
  472. //------------------------------------------------------------------------------
  473. SOM_Scope    void
  474. SOMLINK        ScriptRunner__Initialize
  475.             (
  476.                 SampleCode_ScriptRunner*        somSelf,
  477.                 Environment*                    ev,
  478.                 ODStorageUnit*                    storageUnit
  479.             )
  480. {
  481.     SampleCode_ScriptRunnerData *somThis = SampleCode_ScriptRunnerGetData(somSelf);
  482.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","Initialize");
  483.  
  484.     SOM_TRY
  485.     
  486.     ODSession* session = ODGetSession(ev, storageUnit);
  487.         
  488.     // Check to see if we need to initialize our globals.
  489.     
  490.     if ( gGlobalsUsageCount == 0 )
  491.     {    
  492.         // Create our globals space. We store the globals in a struct so
  493.         // that we can put them in temp mem. Otherwise, CFM loads the globals
  494.         // with the data fragment of a CFM library in the application heap.
  495.         gGlobals = new ScriptRunnerGlobals;
  496.  
  497.         // Load our floating window def proc in case the 7.5 def proc
  498.         // isn't available.
  499.         ODSLong savedRef = BeginUsingLibraryResources();
  500.         {
  501.             gGlobals->fFloatWindowProc = GetResource('WDEF', kFloatWindowDefID);
  502.             DetachResource(gGlobals->fFloatWindowProc);
  503.             
  504.             // Since this version doesn't support recording, load the disabled 
  505.             // Record button.
  506.             gGlobals->fDisabledRecButton = (ODHandle)GetPicture(kRecordDisabledID);
  507.             DetachResource(gGlobals->fDisabledRecButton);
  508.         }
  509.         EndUsingLibraryResources(savedRef);
  510.  
  511.         // We will be using only the modal focus in this part. For
  512.         // convenience, we tokenize the value here and store it for
  513.         // equivalence tests in the activation methods.
  514.         gGlobals->fModalFocus = session->Tokenize(ev, kODModalFocus);
  515.  
  516.         // Tokenize our two presentation values, and the frame view type.
  517.         gGlobals->fPalettePresentation = session->Tokenize(ev, kPalettePresentation);
  518.         gGlobals->fResultPresentation = session->Tokenize(ev, kResultPresentation);
  519.         gGlobals->fFrameView = session->Tokenize(ev, kODViewAsFrame);
  520.  
  521.         // Get the platform value type for 'TEXT' data from OpenDoc. We
  522.         // use this when Dragging the Result from the result window.
  523.         gGlobals->fTextKind = session->GetTranslation(ev)->
  524.                             GetISOTypeFromPlatformType(ev, typeChar, kODPlatformDataType);
  525.                         
  526.         // Instantiate the OSA helper object and open a connection
  527.         // for the scripting component.
  528.         gGlobals->fOSAScripter = new CScripter;
  529.         _fScriptConnection = gGlobals->fOSAScripter->OpenScriptingComponent();
  530.  
  531.         // Set the bounds for the palette and result windows.
  532.         SetRect(&gGlobals->fPaletteBounds, kPaletteOrigin, kPaletteOrigin, 
  533.                             kPaletteOrigin+kPaletteWidth, kPaletteOrigin+kPaletteHeight);
  534.         SetRect(&gGlobals->fResultBounds, kResultOrigin, kResultOrigin, 
  535.                             kResultOrigin+kResultWidth, kResultOrigin+kResultHeight);
  536.     
  537.         // The first client of the global variables is running.
  538.         gGlobalsUsageCount = 1;
  539.     }
  540.     else
  541.     {
  542.         // We keep a "usage" count so that we can null out
  543.         // the global variables when we are finished using them.
  544.         gGlobalsUsageCount++;
  545.     }
  546.     
  547.     SOM_CATCH_ALL
  548.     SOM_ENDTRY
  549. }
  550.  
  551. //------------------------------------------------------------------------------
  552. // Method:        HasExtension
  553. // Origin:        ODObject
  554. //
  555. // Description:    Returns true if asking for the Palette Extension.
  556. //------------------------------------------------------------------------------
  557. SOM_Scope    ODBoolean
  558. SOMLINK        ScriptRunner__HasExtension
  559.             (
  560.                 SampleCode_ScriptRunner*    somSelf,
  561.                 Environment*                ev,
  562.                 ODType                        extensionName
  563.             )
  564. {
  565.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","HasExtension");
  566.     
  567.     return ( ODISOStrEqual(extensionName, kPaletteExtension) );
  568. }
  569.  
  570. //------------------------------------------------------------------------------
  571. // Method:        AcquireExtension
  572. // Origin:        ODObject
  573. //------------------------------------------------------------------------------
  574. SOM_Scope    ODExtension*
  575. SOMLINK        ScriptRunner__AcquireExtension
  576.             (
  577.                 SampleCode_ScriptRunner*    somSelf,
  578.                 Environment*                ev,
  579.                 ODType                        extensionName
  580.             )
  581. {
  582.     SampleCode_ScriptRunnerData *somThis = SampleCode_ScriptRunnerGetData(somSelf);
  583.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","AcquireExtension");
  584.  
  585.     SOM_TRY
  586.         if ( ODISOStrEqual(extensionName, kPaletteExtension) )
  587.         {
  588.             if ( gGlobals->fPaletteExtension == kODNULL )
  589.             {
  590.                  gGlobals->fPaletteExtension = new Samples_PaletteExt;
  591.                  gGlobals->fPaletteExtension->InitExtension(ev, _fSelf);
  592.              }
  593.              
  594.              ODAcquireObject(ev, gGlobals->fPaletteExtension);
  595.         }
  596.     SOM_CATCH_ALL
  597.         ODSafeReleaseObject(gGlobals->fPaletteExtension);
  598.         gGlobals->fPaletteExtension = kODNULL;
  599.     SOM_ENDTRY
  600.  
  601.     return  gGlobals->fPaletteExtension;    
  602. }
  603.  
  604. //------------------------------------------------------------------------------
  605. // Method:        ReleaseExtension
  606. // Origin:        ODObject
  607. //
  608. // Description:    This method is called when the extension's refcount
  609. //                reaches zero. At this point, we delete the object.
  610. //------------------------------------------------------------------------------
  611. SOM_Scope    void
  612. SOMLINK        ScriptRunner__ReleaseExtension
  613.             (
  614.                 SampleCode_ScriptRunner*    somSelf,
  615.                 Environment*                ev,
  616.                 ODExtension*                extension
  617.             )
  618. {
  619.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","ReleaseExtension");
  620.  
  621.     SOM_TRY
  622.         if ( ODObjectsAreEqual(ev, extension, gGlobals->fPaletteExtension) )
  623.             ODDeleteObject(gGlobals->fPaletteExtension);
  624.     SOM_CATCH_ALL
  625.     SOM_ENDTRY
  626. }
  627.  
  628. //------------------------------------------------------------------------------
  629. // Method:        CheckAndAddProperties
  630. // Origin:        ScriptRunner
  631. //
  632. // Description:    This method is called to prepare the storage unit 
  633. //                during the creation of stationery, and to verify 
  634. //                that all the properties we need are present during
  635. //                externalization. .
  636. //
  637. //                The part typically adds the default content property,
  638. //                a preferred editor/viewer property (to aid in part binding), 
  639. //                and a default name for the part.
  640. //------------------------------------------------------------------------------
  641. SOM_Scope    void
  642. SOMLINK        ScriptRunner__CheckAndAddProperties
  643.             (
  644.                 SampleCode_ScriptRunner*    somSelf,
  645.                 Environment*                ev,
  646.                 ODStorageUnit*                storageUnit
  647.             )
  648. {
  649.     SampleCode_ScriptRunnerData *somThis = SampleCode_ScriptRunnerGetData(somSelf);
  650.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","CheckAndAddProperties");
  651.     
  652.     SOM_TRY
  653.         // Create our content property.    
  654.         if ( !storageUnit->Exists(ev, kODPropContents, kODNULL, 0) )
  655.             storageUnit->AddProperty(ev, kODPropContents);
  656.         if ( !storageUnit->Exists(ev, kODPropContents, kScriptRunnerKind, 0) )
  657.         {
  658.             storageUnit->Focus(ev, kODPropContents, kODPosUndefined, kODNULL, 
  659.                                     0, kODPosUndefined);
  660.             storageUnit->AddValue(ev, kScriptRunnerKind);
  661.         }
  662.     SOM_CATCH_ALL
  663.     SOM_ENDTRY
  664. }
  665.  
  666. //------------------------------------------------------------------------------
  667. // Method:        Open
  668. // Origin:        ODPart
  669. //
  670. // Description:    Typically, this method is called when OpenDoc, a containing 
  671. //                part, or the active editor/viewer would like to open a frame
  672. //                into a seperate window. If a source frame is passed into
  673. //                this method, the editor/viewer is being asked to open a
  674. //                part window.
  675. //
  676. //                However, for the ScriptRunner part, this method is called
  677. //                by the ScriptRunnerAgent object, after it created this part.
  678. //------------------------------------------------------------------------------
  679. SOM_Scope    ODID
  680. SOMLINK        ScriptRunner__Open
  681.             (
  682.                 SampleCode_ScriptRunner*    somSelf,
  683.                 Environment*                ev,
  684.                 ODFrame*                    frame
  685.             )
  686. {
  687.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","Open");
  688.  
  689.     SOM_TRY
  690.         if ( frame == kODNULL )
  691.         {
  692.             Str63 windowTitle;
  693.             
  694.             // Get the window title string from our library's resources.
  695.             // (Note: ODGetIndString focuses the resource fork for us)
  696.             ODGetIndString(windowTitle, kStringResID, kScriptRunnerIndex);
  697.  
  698.             // Create the floating palette window.
  699.             TempODWindow window = somSelf->CreateWindow(ev, gGlobals->fPalettePresentation,
  700.                                     floatProc, windowTitle, &gGlobals->fPaletteBounds);
  701.             THROW_IF_NULL(window);
  702.             
  703.             somSelf->LoadPalette(ev);
  704.             window->Open(ev);
  705.             gGlobals->fPaletteID = window->GetID(ev);
  706.         }
  707.         else
  708.             THROW(kODErrInvalidFrame);
  709.     SOM_CATCH_ALL
  710.     SOM_ENDTRY
  711.  
  712.     return gGlobals->fPaletteID;
  713. }
  714.  
  715. //------------------------------------------------------------------------------
  716. // Method:        Draw
  717. // Origin:        ODPart
  718. //
  719. // Description:    This method is called when a facet of a part's display
  720. //                frame intersects the invalidated portion of an OpenDoc
  721. //                window. The invalidShape parameter passed in is the
  722. //                portion of the facet which has been invalidated.
  723. //------------------------------------------------------------------------------
  724. SOM_Scope    void
  725. SOMLINK        ScriptRunner__Draw
  726.             (
  727.                 SampleCode_ScriptRunner*        somSelf,
  728.                 Environment*                    ev,
  729.                 ODFacet*                        facet,
  730.                 ODShape*                        invalidShape
  731.             )
  732. {
  733.     SampleCode_ScriptRunnerData *somThis = SampleCode_ScriptRunnerGetData(somSelf);
  734.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner", "Draw");
  735.  
  736.     SOM_TRY
  737.         ODFrame* frame = facet->GetFrame(ev);
  738.         
  739.         if ( frame->GetPresentation(ev) == gGlobals->fPalettePresentation && 
  740.                     gGlobals->fPaletteVisible )
  741.         {
  742.             // Focus the port and origin for drawing in our facet. Note that
  743.             // this instance of the CFocus class is being allocated. When the
  744.             // execution leaves the scope of this method, the destructor is
  745.             // automatically called and cleans up the drawing environment.
  746.             CFocus initiateDrawing(ev, facet);
  747.             
  748.             TempODShape frameShape = frame->AcquireFrameShape(ev, kODNULL);
  749.             RgnHandle rgn = frameShape->GetQDRegion(ev);
  750.             Rect bounds = (**rgn).rgnBBox;
  751.  
  752.             DrawPicture((PicHandle)gGlobals->fPalette, &bounds);        
  753.     
  754.             // Draw the "disabled" Recording button (for now).
  755.             DrawPicture((PicHandle)gGlobals->fDisabledRecButton, &gRecordButton);
  756.         }
  757.         else if ( gGlobals->fResultWindowVisible )
  758.         {
  759.             somSelf->DisplayResult(ev);
  760.         }    
  761.     SOM_CATCH_ALL
  762.     SOM_ENDTRY
  763. }
  764.  
  765. //------------------------------------------------------------------------------
  766. // Method:        DisplayFrameAdded
  767. // Origin:        ODPart
  768. //
  769. // Description:    This method is called in response to a frame being
  770. //                created for our part.
  771. //------------------------------------------------------------------------------
  772. SOM_Scope    void
  773. SOMLINK        ScriptRunner__DisplayFrameAdded
  774.             (
  775.                 SampleCode_ScriptRunner*    somSelf,
  776.                 Environment*                ev,
  777.                 ODFrame*                    frame
  778.             )
  779. {
  780.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","DisplayFrameAdded");
  781. }
  782.  
  783. //------------------------------------------------------------------------------
  784. // Method:        DisplayFrameRemoved
  785. // Origin:        ODPart
  786. //
  787. // Description:    This method is called in response to a frame being
  788. //                removed from our part and the draft.
  789. //------------------------------------------------------------------------------
  790. SOM_Scope    void
  791. SOMLINK        ScriptRunner__DisplayFrameRemoved
  792.             (
  793.                 SampleCode_ScriptRunner*        somSelf,
  794.                 Environment*                    ev,
  795.                 ODFrame*                        frame
  796.             )
  797. {
  798.     SampleCode_ScriptRunnerData *somThis = SampleCode_ScriptRunnerGetData(somSelf);
  799.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","DisplayFrameRemoved");
  800.  
  801.     SOM_TRY
  802.         ODArbitrator* arbitrator = ODGetSession(ev, _fSelf)->GetArbitrator(ev);
  803.         
  804.         // Make sure the frame going away doesn't own any foci. Forgetting
  805.         // to do this will cause a "refcounting" error when the frame
  806.         // is deleted by the draft.
  807.         TempODFrame focusFrame = arbitrator->AcquireFocusOwner(ev, gGlobals->fModalFocus);
  808.         if ( ODObjectsAreEqual(ev, focusFrame, frame) )
  809.             arbitrator->RelinquishFocus(ev, gGlobals->fModalFocus, frame);
  810.  
  811.          // Clean up the window associated with this frame.
  812.         TempODWindow window = frame->AcquireWindow(ev);
  813.         THROW_IF_NULL(window);
  814.         
  815.         ODPlatformWindow windowPtr = window->GetPlatformWindow(ev);
  816.         CloseWindow(windowPtr);
  817.         ODDisposePtr(windowPtr);
  818.     SOM_CATCH_ALL
  819.     SOM_ENDTRY
  820. }
  821.  
  822. //------------------------------------------------------------------------------
  823. // Method:        DisplayFrameClosed
  824. // Origin:        ODPart
  825. //
  826. // Description:    This method is called in response to a frame being
  827. //                closed but not removed from the draft.
  828. //------------------------------------------------------------------------------
  829. SOM_Scope    void
  830. SOMLINK        ScriptRunner__DisplayFrameClosed
  831.             (
  832.                 SampleCode_ScriptRunner*    somSelf,
  833.                 Environment*                ev,
  834.                 ODFrame*                    frame
  835.             )
  836. {
  837.     SampleCode_ScriptRunnerData *somThis = SampleCode_ScriptRunnerGetData(somSelf);
  838.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","DisplayFrameClosed");
  839.  
  840.     SOM_TRY
  841.         ODArbitrator* arbitrator = ODGetSession(ev, _fSelf)->GetArbitrator(ev);
  842.     
  843.         TempODFrame focusFrame = arbitrator->AcquireFocusOwner(ev, gGlobals->fModalFocus);
  844.         if ( ODObjectsAreEqual(ev, focusFrame, frame) )
  845.             arbitrator->RelinquishFocus(ev, gGlobals->fModalFocus, frame);
  846.  
  847.          // Clean up the window associated with this frame.
  848.         TempODWindow window = frame->AcquireWindow(ev);
  849.         THROW_IF_NULL(window);
  850.         
  851.         ODPlatformWindow windowPtr = window->GetPlatformWindow(ev);
  852.         CloseWindow(windowPtr);
  853.         ODDisposePtr(windowPtr);
  854.     SOM_CATCH_ALL
  855.     SOM_ENDTRY
  856. }
  857.  
  858. //------------------------------------------------------------------------------
  859. // Method:        DisplayFrameConnected
  860. // Origin:        ODPart
  861. //
  862. // Description:    This method is called when one of our display frames,
  863. //                previously written out, is internalized. This method
  864. //                is called instead of DisplayFrameAdded because a "new"
  865. //                frame is not being created; an existing one is being
  866. //                reconstituted.
  867. //------------------------------------------------------------------------------
  868. SOM_Scope    void
  869. SOMLINK        ScriptRunner__DisplayFrameConnected
  870.             (
  871.                 SampleCode_ScriptRunner*    somSelf,
  872.                 Environment*                ev,
  873.                 ODFrame*                    frame
  874.             )
  875. {
  876.     SampleCode_ScriptRunnerData *somThis = SampleCode_ScriptRunnerGetData(somSelf);
  877.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","DisplayFrameConnected");
  878.  
  879.     // This method never gets called since we don't externalize
  880.     // our display frames, but must be overridden.
  881. }
  882.  
  883. //------------------------------------------------------------------------------
  884. // Method:        ViewTypeChanged
  885. // Origin:        ODPart
  886. //
  887. // Description:    This method is called when one of our display frame's
  888. //                viewType field has been modified. We call this
  889. //                method on ourselves when new display frames are
  890. //                added, but it can also be called when the user
  891. //                changes the view in the "part info" dialog.
  892. //------------------------------------------------------------------------------
  893. SOM_Scope    void
  894. SOMLINK        ScriptRunner__ViewTypeChanged
  895.             (
  896.                 SampleCode_ScriptRunner*        somSelf,
  897.                 Environment*                    ev,
  898.                 ODFrame*                        frame
  899.             )
  900. {
  901.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","ViewTypeChanged");
  902.  
  903.     SOM_TRY
  904.         // ScriptRunner only allows "frame" view.
  905.         if ( frame->GetViewType(ev) != gGlobals->fFrameView )
  906.             frame->SetViewType(ev, gGlobals->fFrameView);
  907.     SOM_CATCH_ALL
  908.     SOM_ENDTRY
  909. }
  910.  
  911. //------------------------------------------------------------------------------
  912. // Method:        BeginRelinquishFocus
  913. // Origin:        ODPart
  914. //
  915. // Description:    This method is called when another part (or possibly
  916. //                ourself) is requesting a focus for one of its display
  917. //                frames. Returning true means we are willing to give
  918. //                up the requested focus.
  919. //
  920. //                The part will give up any focus except for the
  921. //                modal focus. We don't want to give this up until we
  922. //                are completely done displaying a modal dialog.
  923. //------------------------------------------------------------------------------
  924. SOM_Scope    ODBoolean
  925. SOMLINK        ScriptRunner__BeginRelinquishFocus
  926.             (
  927.                 SampleCode_ScriptRunner*        somSelf,
  928.                 Environment*                    ev,
  929.                 ODTypeToken                        focus,
  930.                 ODFrame*                        /*ownerFrame*/,
  931.                 ODFrame*                        proposedFrame
  932.             )
  933. {
  934.     SampleCode_ScriptRunnerData *somThis = SampleCode_ScriptRunnerGetData(somSelf);
  935.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","BeginRelinquishFocus");
  936.  
  937.     ODBoolean willRelinquish = kODTrue;
  938.  
  939.     SOM_TRY
  940.         // Another part is trying to put up a Modal dialog while we
  941.         // are currently displaying ours. Deny the request.
  942.         if ( focus == gGlobals->fModalFocus )
  943.         {
  944.             TempODPart proposedPart = proposedFrame->AcquirePart(ev);
  945.             if ( ODObjectsAreEqual(ev, proposedPart, _fSelf) == kODFalse )
  946.                 willRelinquish = kODFalse;
  947.         }        
  948.     SOM_CATCH_ALL
  949.     SOM_ENDTRY
  950.  
  951.     return willRelinquish;
  952. }
  953.  
  954. //------------------------------------------------------------------------------
  955. // Method:        CommitRelinquishFocus
  956. // Origin:        ODPart
  957. //
  958. // Description:    This method is called when it is actually time to give
  959. //                up the requested focus.
  960. //
  961. //                The part calls its FocusLost method to handle the 
  962. //                reliquishing of the particular focus.
  963. //------------------------------------------------------------------------------
  964. SOM_Scope    void
  965. SOMLINK        ScriptRunner__CommitRelinquishFocus
  966.             (
  967.                 SampleCode_ScriptRunner*        somSelf,
  968.                 Environment*                    ev,
  969.                 ODTypeToken                        focus,
  970.                 ODFrame*                        ownerFrame,
  971.                 ODFrame*                        proposedFrame
  972.             )
  973. {
  974.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","CommitRelinquishFocus");
  975.  
  976.     SOM_TRY
  977.         // We agreed to give up the requested focus, so now we must do so.
  978.         somSelf->FocusLost(ev, focus, ownerFrame);
  979.     SOM_CATCH_ALL
  980.     SOM_ENDTRY
  981. }
  982.  
  983. //------------------------------------------------------------------------------
  984. // Method:        AbortRelinquishFocus
  985. // Origin:        ODPart
  986. //
  987. // Description:    This method is called when another part (or ourself) requested
  988. //                a focus for one of its display frames, bet we returned kODFalse
  989. //                from BeginRelinqishFocus() for one, or all, of the requested
  990. //                foci. At this point, we are being told to resume ownership of 
  991. //                the focus.
  992. //
  993. //                The part calls its FocusAcquired method to handle the 
  994. //                re-acquisition of the particular focus.
  995. //------------------------------------------------------------------------------
  996. SOM_Scope    void
  997. SOMLINK        ScriptRunner__AbortRelinquishFocus
  998.             (
  999.                 SampleCode_ScriptRunner*        somSelf,
  1000.                 Environment*                    ev,
  1001.                 ODTypeToken                        focus,
  1002.                 ODFrame*                        ownerFrame,
  1003.                 ODFrame*                        /*proposedFrame*/
  1004.             )
  1005. {
  1006.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","AbortRelinquishFocus");
  1007.     
  1008.     // Some parts may have suspended some events in the BeginRelinquishFocus
  1009.     // method. If so, they would resume those events here.
  1010. }
  1011.  
  1012. //------------------------------------------------------------------------------
  1013. // Method:        FocusAcquired
  1014. // Origin:        ODPart
  1015. //
  1016. // Description:    This method is called when the Arbitrator has
  1017. //                registered us as the "owner" of the particular focus.
  1018. //                This can occur if a focus is requested, or if a focus
  1019. //                is tranferred to one of the part's display frames.
  1020. //------------------------------------------------------------------------------
  1021. SOM_Scope    void
  1022. SOMLINK        ScriptRunner__FocusAcquired
  1023.             (
  1024.                 SampleCode_ScriptRunner*        somSelf,
  1025.                 Environment*                    ev,
  1026.                 ODTypeToken                        focus,
  1027.                 ODFrame*                        ownerFrame
  1028.             )
  1029.  
  1030. {
  1031.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","FocusAcquired");
  1032. }
  1033.  
  1034. //------------------------------------------------------------------------------
  1035. // Method:        FocusLost
  1036. // Origin:        ODPart
  1037. //
  1038. // Description:    This method is called when the Arbitrator has
  1039. //                unregistered us as the owner of a particular focus.
  1040. //------------------------------------------------------------------------------
  1041. SOM_Scope    void
  1042. SOMLINK        ScriptRunner__FocusLost
  1043.             (
  1044.                 SampleCode_ScriptRunner*    somSelf,
  1045.                 Environment*                ev,
  1046.                 ODTypeToken                    focus,
  1047.                 ODFrame*                    ownerFrame
  1048.             )
  1049. {
  1050.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","FocusLost");
  1051. }
  1052.  
  1053. //------------------------------------------------------------------------------
  1054. // Method:        HandleEvent
  1055. // Origin:        ODPart
  1056. //
  1057. // Description:    The method is called when an event occurs within one of
  1058. //                our owned foci. The exception to this case are "mouse 
  1059. //                movement" events and embedded frame events, which can occur
  1060. //                when a part owns no foci.
  1061. //
  1062. //                The part returns true if the event was handled.
  1063. //------------------------------------------------------------------------------
  1064. SOM_Scope    ODBoolean
  1065. SOMLINK        ScriptRunner__HandleEvent
  1066.             (
  1067.                 SampleCode_ScriptRunner*        somSelf,
  1068.                 Environment*                    ev,
  1069.                 ODEventData*                    event,
  1070.                 ODFrame*                        frame,
  1071.                 ODFacet*                        facet,
  1072.                 ODEventInfo*                    eventInfo
  1073.             )
  1074. {
  1075.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","HandleEvent");
  1076.  
  1077.     ODBoolean    eventHandled = kODFalse;
  1078.  
  1079.     SOM_TRY    
  1080.         // Event handling is basically the same as standard 
  1081.         // Macintosh applications, except that the events have 
  1082.         // been renamed for cross-platform compatability.
  1083.         
  1084.         switch( event->what )
  1085.         {
  1086.             case kODEvtMouseUp:
  1087.             case kODEvtMouseDown:
  1088.                 eventHandled = somSelf->HandleMouseEvent(ev, event, 
  1089.                                             eventInfo, frame, facet);
  1090.                 break;
  1091.         
  1092.             case kODEvtWindow:
  1093.                 eventHandled = somSelf->HandleWindowEvent(ev, event, frame);
  1094.                 break;
  1095.     
  1096.             default:
  1097.                 break;
  1098.         }
  1099.     SOM_CATCH_ALL
  1100.     SOM_ENDTRY
  1101.  
  1102.     return eventHandled;
  1103. }
  1104.  
  1105. //------------------------------------------------------------------------------
  1106. // Method:        HandleOSAEvent
  1107. // Origin:        ScriptRunner
  1108. //------------------------------------------------------------------------------
  1109. SOM_Scope    void
  1110. SOMLINK        ScriptRunner__HandleOSAEvent
  1111.              (
  1112.                 SampleCode_ScriptRunner*        somSelf,
  1113.                 Environment*                    ev,
  1114.                 ODFrame*                        frame,
  1115.                 ODCommandID                        command
  1116.             )
  1117. {
  1118.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","HandleOSAEvent");
  1119.     
  1120.     ODByteArray            data;
  1121.  
  1122.     SOM_TRY
  1123.         switch( command )
  1124.         {
  1125.             case kRecordCommand:
  1126.                 // Not handled yet.
  1127.                 break;
  1128.     
  1129.             case kStopCommand:
  1130.                 break;
  1131.     
  1132.             case kRunCommand:
  1133.                 // Dispose of the result value before executing a new  script.
  1134.                 if ( gGlobals->fResultValue != kODNULL )
  1135.                 {
  1136.                     ODDisposePtr(gGlobals->fResultValue);
  1137.                     gGlobals->fResultValue = kODNULL;
  1138.                 }
  1139.  
  1140.                 if ( gGlobals->fTextTransferExt->GetData(ev, typeChar, &data) )
  1141.                 {
  1142.                 TRY
  1143.                     gGlobals->fOSAScripter->SetScriptSourceBA(typeChar, &data);
  1144.                     gGlobals->fOSAScripter->DoRun();
  1145.                 CATCH_ALL
  1146.                     DisposeByteArrayStruct(data);
  1147.                     RERAISE;
  1148.                 ENDTRY
  1149.                     DisposeByteArrayStruct(data);
  1150.                     
  1151.                     somSelf->SetClientTextData(ev);
  1152.                     somSelf->DisplayResult(ev);        
  1153.                 }
  1154.                 break;
  1155.                 
  1156.             case kCompileCommand:
  1157.                 if ( gGlobals->fTextTransferExt->GetData(ev, typeChar, &data) )
  1158.                 {
  1159.                 TRY
  1160.                     gGlobals->fOSAScripter->SetScriptSourceBA(typeChar, &data);
  1161.                     gGlobals->fOSAScripter->DoCompile();
  1162.                 CATCH_ALL
  1163.                     DisposeByteArrayStruct(data);
  1164.                     RERAISE;
  1165.                 ENDTRY
  1166.                     DisposeByteArrayStruct(data);
  1167.                     
  1168.                     somSelf->SetClientTextData(ev);
  1169.                 }
  1170.                 break;
  1171.                 
  1172.             default:
  1173.                 break;
  1174.         }
  1175.     SOM_CATCH_ALL
  1176.         somSelf->DoErrorDialog(ev, frame);
  1177.         // Change the error code value so the DocShell doesn't
  1178.         // display an error dialog.
  1179.         SetErrorCode(kODErrAlreadyNotified);
  1180.     SOM_ENDTRY
  1181. }
  1182.  
  1183. //------------------------------------------------------------------------------
  1184. // Method:        HandleWindowEvent
  1185. // Origin:        ScriptRunner
  1186. //
  1187. // Description:    This method is called by the part to handle window events.
  1188. //------------------------------------------------------------------------------
  1189. SOM_Scope    ODBoolean
  1190. SOMLINK        ScriptRunner__HandleWindowEvent
  1191.             (
  1192.                 SampleCode_ScriptRunner*        somSelf,
  1193.                 Environment*                    ev,
  1194.                 ODEventData*                    event,
  1195.                 ODFrame*                        frame
  1196.             )
  1197. {
  1198.     SampleCode_ScriptRunnerData *somThis = SampleCode_ScriptRunnerGetData(somSelf);
  1199.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","HandleWindowEvent");
  1200.  
  1201.     ODBoolean handled = kODFalse;
  1202.  
  1203.     SOM_TRY
  1204.         switch( event->message )
  1205.         {
  1206.             case inGoAway:
  1207.                 if ( frame->GetPresentation(ev) == gGlobals->fPalettePresentation )
  1208.                     somSelf->HidePalette(ev);
  1209.                 else
  1210.                     somSelf->HideResultWindow(ev);
  1211.                     
  1212.                 handled = kODTrue;
  1213.                 break;
  1214.  
  1215.             default:
  1216.                 break;
  1217.         }
  1218.     SOM_CATCH_ALL
  1219.     SOM_ENDTRY
  1220.  
  1221.     return handled;
  1222. }
  1223.  
  1224. //------------------------------------------------------------------------------
  1225. // Method:        HandleMouseEvent
  1226. // Origin:        ScriptRunner
  1227. //
  1228. // Description:    This method is called when a mouse event is received.
  1229. //                When a frame is inactive, the first mouse up event
  1230. //                activates it (inactive frames do not receive
  1231. //                kODEvtMouseDown events).
  1232. //
  1233. //                The mouse down event is handled in the Result window
  1234. //                to determine if the user is dragging the result value.
  1235. //------------------------------------------------------------------------------
  1236. SOM_Scope    ODBoolean
  1237. SOMLINK        ScriptRunner__HandleMouseEvent
  1238.             (
  1239.                 SampleCode_ScriptRunner*        somSelf,
  1240.                 Environment*                    ev,
  1241.                 ODEventData*                    event,
  1242.                 ODEventInfo*                    eventInfo,
  1243.                 ODFrame*                        frame,
  1244.                 ODFacet*                        facet
  1245.             )
  1246. {
  1247.     SampleCode_ScriptRunnerData *somThis = SampleCode_ScriptRunnerGetData(somSelf);
  1248.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","HandleMouseEvent");
  1249.  
  1250.     SOM_TRY
  1251.         // If the facet parameter is invalid, the mouse up occurred outside the
  1252.         // bounds of a Modal window, otherwise it should be treated normally.
  1253.         if ( facet != kODNULL )
  1254.         {
  1255.             if ( event->what == kODEvtMouseUp )
  1256.             {
  1257.                 ODWindow* window = facet->GetWindow(ev);
  1258.     
  1259.                     // Activate inactive windows on the first mouse up event.
  1260.                     if ( !window->IsActive(ev) )
  1261.                         window->Select(ev);
  1262.                     else
  1263.                         somSelf->HandleMouseUp(ev, eventInfo, frame);
  1264.             }
  1265.             else if ( event->what == kODEvtMouseDown )                
  1266.             {
  1267.                 // Check which window the mouse event occurred in.
  1268.                 if ( frame->GetPresentation(ev) == gGlobals->fPalettePresentation )
  1269.                     somSelf->HandleMouseDown(ev, eventInfo, facet);
  1270.                 else        
  1271.                 {
  1272.                     if ( WaitMouseMoved(event->where) )
  1273.                         somSelf->InitiateDrag(ev, event, facet, &(eventInfo->where));
  1274.                 }
  1275.             }
  1276.         }
  1277.     SOM_CATCH_ALL
  1278.     SOM_ENDTRY
  1279.  
  1280.     return kODTrue;
  1281. }
  1282.  
  1283. //------------------------------------------------------------------------------
  1284. // Method:        HandleMouseUp
  1285. // Origin:        ScriptRunner
  1286. //
  1287. // Description:    This method is called by the part when a mouse event
  1288. //                is recieved.
  1289. //
  1290. //                If the user mouses up in the controls palette over an
  1291. //                active button, perform the corresponding action.
  1292. //------------------------------------------------------------------------------
  1293. SOM_Scope    void
  1294. SOMLINK        ScriptRunner__HandleMouseUp
  1295.             (
  1296.                 SampleCode_ScriptRunner*        somSelf,
  1297.                 Environment*                    ev,
  1298.                 ODEventInfo*                    eventInfo,
  1299.                 ODFrame*                        frame
  1300.             )
  1301. {
  1302.     SampleCode_ScriptRunnerData *somThis = SampleCode_ScriptRunnerGetData(somSelf);
  1303.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","HandleMouseUp");
  1304.     
  1305.     Rect        buttonRect;
  1306.     Point        where;
  1307.  
  1308.     SOM_TRY
  1309.         // Get the localized mouse coordinates from the Event Info.
  1310.         where.h = FixedToInt(eventInfo->where.x);
  1311.         where.v = FixedToInt(eventInfo->where.y);
  1312.     
  1313.         if ( PtInRect(where, &gStopButton) && (_fButton == kStopCommand) )
  1314.             somSelf->HandleOSAEvent(ev, frame, kStopCommand);
  1315.         else if ( PtInRect(where, &gRunButton) && (_fButton == kRunCommand) )
  1316.             somSelf->HandleOSAEvent(ev, frame, kRunCommand);
  1317.         else if ( PtInRect(where, &gCompileButton) && (_fButton == kCompileCommand) )
  1318.             somSelf->HandleOSAEvent(ev, frame, kCompileCommand);
  1319.     
  1320.         ODBoolean refreshButtons = kODTrue;
  1321.     
  1322.         // The button that was pressed must be the one that is refreshed
  1323.         switch ( _fButton )
  1324.         {
  1325.             case kRecordCommand:    buttonRect = gRecordButton;
  1326.                                     break;
  1327.     
  1328.             case kStopCommand:        buttonRect = gStopButton;
  1329.                                     break;
  1330.     
  1331.             case kRunCommand:        buttonRect = gRunButton;
  1332.                                     break;
  1333.         
  1334.             case kCompileCommand:    buttonRect = gCompileButton;
  1335.                                     break;
  1336.                         
  1337.             default:                refreshButtons = kODFalse;
  1338.         }
  1339.     
  1340.         // Invalidate the button that was pressed.
  1341.         if ( refreshButtons )
  1342.             InvalidateRect(ev, frame, buttonRect);
  1343.             
  1344.         _fButton = kODNULLID;
  1345.     SOM_CATCH_ALL
  1346.     SOM_ENDTRY
  1347. }
  1348.  
  1349. //------------------------------------------------------------------------------
  1350. // Method:        HandleMouseDown
  1351. // Origin:        ScriptRunner
  1352. //
  1353. // Description:    This method is called by the part when a mouse event
  1354. //                is received.
  1355. //
  1356. //                If the controls palette is showing, the mouse downs
  1357. //                are handled on the buttons.
  1358. //------------------------------------------------------------------------------
  1359. SOM_Scope    void
  1360. SOMLINK        ScriptRunner__HandleMouseDown
  1361.             (
  1362.                 SampleCode_ScriptRunner*        somSelf,
  1363.                 Environment*                    ev,
  1364.                 ODEventInfo*                    eventInfo,
  1365.                 ODFacet*                        facet
  1366.             )
  1367. {
  1368.     SampleCode_ScriptRunnerData *somThis = SampleCode_ScriptRunnerGetData(somSelf);
  1369.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","HandleMouseDown");
  1370.  
  1371.     Rect            buttonRect;
  1372.     PicHandle        buttonPICT;
  1373.     Point             where;
  1374.     ODUShort        buttonID = kODNULLID;
  1375.  
  1376.     SOM_TRY
  1377.         // Get the localized mouse coordinates from the Event Info.
  1378.         where.h = FixedToInt(eventInfo->where.x);
  1379.         where.v = FixedToInt(eventInfo->where.y);
  1380.     
  1381.         if ( PtInRect(where, &gStopButton) )
  1382.         {
  1383.             _fButton = kStopCommand;
  1384.             buttonID = kStopPressedID;
  1385.             buttonRect = gStopButton;
  1386.         }
  1387.         else if ( PtInRect(where, &gRunButton) )
  1388.         {
  1389.             _fButton = kRunCommand;
  1390.             buttonID = kRunPressedID;
  1391.             buttonRect = gRunButton;
  1392.         }
  1393.         else if ( (PtInRect(where, &gCompileButton)) )
  1394.         {
  1395.             _fButton = kCompileCommand;
  1396.             buttonID = kCompilePressedID;
  1397.             buttonRect = gCompileButton;
  1398.         }
  1399.     
  1400.         // If valid, draw the control button in its "pressed" state.
  1401.         if ( buttonID )
  1402.         {
  1403.             CUsingLibraryResources res;
  1404.     
  1405.             CFocus initiateDrawing(ev, facet);
  1406.             buttonPICT = GetPicture(buttonID);
  1407.             DrawPicture(buttonPICT, &buttonRect);
  1408.         }
  1409.     SOM_CATCH_ALL
  1410.     SOM_ENDTRY
  1411. }
  1412.  
  1413. //------------------------------------------------------------------------------
  1414. // Method:        CreateWindow
  1415. // Origin:        ScriptRunner
  1416. //
  1417. // Description:    This method is called by the palette extension when the
  1418. //                palette window needs to be created.
  1419. //------------------------------------------------------------------------------
  1420. SOM_Scope    ODWindow*
  1421. SOMLINK        ScriptRunner__CreateWindow
  1422.              (
  1423.                  SampleCode_ScriptRunner*        somSelf,
  1424.                  Environment*                    ev,
  1425.                  ODTypeToken                        presentation,
  1426.                  ODSShort                        procID,
  1427.                  Str63                            windowTitle,
  1428.                  Rect*                            windowBounds
  1429.              )
  1430. {
  1431.     SampleCode_ScriptRunnerData *somThis = SampleCode_ScriptRunnerGetData(somSelf);
  1432.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","CreateWindow");
  1433.  
  1434.     ODPlatformWindow    platformWindow    = kODNULL;
  1435.     ODWindow*            window            = kODNULL;
  1436.     ODBoolean            resizeable;
  1437.  
  1438.     ODVolatile(platformWindow);
  1439.     
  1440.     SOM_TRY
  1441.  
  1442.     ODPtr wStorage = ODNewPtr(sizeof(WindowRecord));
  1443.     // Create the floating palette with the 7.5 window proc.    
  1444.     platformWindow = NewCWindow(wStorage,
  1445.                                 windowBounds,
  1446.                                 windowTitle,
  1447.                                 kODFalse,            // visible flag
  1448.                                 procID,
  1449.                                 (WindowPtr)-1L,
  1450.                                 kODTrue,
  1451.                                 kODNULL);
  1452.  
  1453.     if ( platformWindow == kODNULL && procID == floatProc )
  1454.     {
  1455.         // If NewCWindow returned NULL when trying to create a floating
  1456.         // window, then we may be running on a pre-7.5 system.
  1457.         platformWindow = NewCWindow(wStorage,
  1458.                                     windowBounds,
  1459.                                     windowTitle,
  1460.                                     kODFalse,
  1461.                                     kFloatWindowDefID * 16,
  1462.                                     (WindowPtr)-1L,
  1463.                                     kODTrue,
  1464.                                     kODNULL);
  1465.  
  1466.         // Substitute our window proc for the 7.5 window proc that was loaded..
  1467.         if ( platformWindow )
  1468.         {
  1469.             Handle tempProc = ((WindowPeek)platformWindow)->windowDefProc;
  1470.             ((WindowPeek)platformWindow)->windowDefProc = gGlobals->fFloatWindowProc;
  1471.             ReleaseResource(tempProc);
  1472.         }
  1473.     }
  1474.     
  1475.     if ( platformWindow )
  1476.     {
  1477.         resizeable = (presentation == gGlobals->fPalettePresentation) ? kODFalse : kODTrue;    
  1478.         ODWindowState* windowState = ODGetSession(ev, _fSelf)->GetWindowState(ev);
  1479.                     
  1480.         // Tell OpenDoc about it by creating an OpenDoc window object.
  1481.         window = windowState->RegisterWindow(ev, 
  1482.                         platformWindow,                    // Macintosh WindowPtr
  1483.                         kODNonPersistentFrameObject,    // Frame type (Persistent/Non-persistent)
  1484.                         kODFalse,                        // Is this a document/root window?
  1485.                         resizeable,                        // Is this window resizeable?
  1486.                         kODTrue,                        // Is this window floating?
  1487.                         kODFalse,                        // Should this window be persistent?
  1488.                         kODFalse,                        // Should this window be disposed?
  1489.                         _fSelf,                            // Part reference to us
  1490.                         gGlobals->fFrameView,            // What view should the window have?
  1491.                         presentation,                    // The presentation the window should have.
  1492.                         kODNULL);                        // The display frame being opened, if any
  1493.     }
  1494.  
  1495.     SOM_CATCH_ALL
  1496.         if ( platformWindow )
  1497.         {
  1498.             // Cleanup Macintosh Window.
  1499.             CloseWindow(platformWindow);
  1500.             ODDisposePtr(platformWindow);
  1501.         }
  1502.     SOM_ENDTRY
  1503.  
  1504.     return window;
  1505. }
  1506.  
  1507. //------------------------------------------------------------------------------
  1508. // Method:        AcquireWindowByID
  1509. // Origin:        ScriptRunner
  1510. //
  1511. // Description:    Return the palette window.
  1512. //------------------------------------------------------------------------------
  1513. SOM_Scope    ODWindow*
  1514. SOMLINK        ScriptRunner__AcquireWindowByID
  1515.              (
  1516.                  SampleCode_ScriptRunner*        somSelf,
  1517.                  Environment*                    ev,
  1518.                  ODID                            windowID
  1519.              )
  1520. {
  1521.     SampleCode_ScriptRunnerData *somThis = SampleCode_ScriptRunnerGetData(somSelf);
  1522.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","AcquireWindowByID");
  1523.  
  1524.     ODWindow*    window;
  1525.     
  1526.     SOM_TRY
  1527.         window = ODGetSession(ev, _fSelf)->GetWindowState(ev)
  1528.                             ->AcquireWindow(ev, windowID);
  1529.     SOM_CATCH_ALL
  1530.         window = kODNULL;
  1531.     SOM_ENDTRY
  1532.     
  1533.     return window;
  1534. }
  1535.  
  1536. //------------------------------------------------------------------------------
  1537. // Method:        SetClient
  1538. // Origin:        ScriptRunner
  1539. //
  1540. // Description:    The client part has changed to another part of the
  1541. //                same type.
  1542. //------------------------------------------------------------------------------
  1543. SOM_Scope    void
  1544. SOMLINK        ScriptRunner__SetClient
  1545.              (
  1546.                  SampleCode_ScriptRunner*        somSelf,
  1547.                  Environment*                    ev,
  1548.                 ODPart*                            client
  1549.              )
  1550. {
  1551.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","SetClient");
  1552.     
  1553.     SOM_TRY
  1554.         if ( !ODObjectsAreEqual(ev, client, gGlobals->fClient) )
  1555.         {
  1556.             if ( gGlobals->fTextTransferExt )
  1557.                 ODReleaseObject(ev, gGlobals->fTextTransferExt);
  1558.             
  1559.             if ( client->HasExtension(ev, kTextTransferExtension) )
  1560.             {
  1561.                 // Acquire the Text Transfer Extension.
  1562.                 gGlobals->fTextTransferExt = (TextTransferExt*)client
  1563.                                 ->AcquireExtension(ev, kTextTransferExtension);
  1564.             }
  1565.             
  1566.             gGlobals->fClient = client;
  1567.         }
  1568.     SOM_CATCH_ALL
  1569.     SOM_ENDTRY
  1570. }
  1571.  
  1572. //------------------------------------------------------------------------------
  1573. // Method:        SetClientTextData
  1574. // Origin:        ScriptRunner
  1575. //
  1576. // Description:    After compiling/executing a script, set the text data of
  1577. //                the client.
  1578. //------------------------------------------------------------------------------
  1579. SOM_Scope    void
  1580. SOMLINK        ScriptRunner__SetClientTextData
  1581.              (
  1582.                  SampleCode_ScriptRunner*        somSelf,
  1583.                  Environment*                    ev
  1584.              )
  1585. {
  1586.     SampleCode_ScriptRunnerData *somThis = SampleCode_ScriptRunnerGetData(somSelf);
  1587.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","SetClientTextData");
  1588.     
  1589.     ODByteArray    textData;
  1590.      ODBoolean    successful;
  1591.  
  1592.     SOM_TRY
  1593.         gGlobals->fOSAScripter->DoDecompile();
  1594.  
  1595.          // First try setting the client's text to reflect the styled text
  1596.          // of a compiled script.
  1597.          if ( gGlobals->fOSAScripter->GetScriptSourceBA('stxt', &textData) )
  1598.          {
  1599.             successful = gGlobals->fTextTransferExt->SetData(ev, 'stxt', &textData);
  1600.             DisposeByteArrayStruct(textData);
  1601.         }
  1602.         
  1603.         // Styled text failed. Try plain text.
  1604.         if ( !successful )
  1605.         {
  1606.             if ( gGlobals->fOSAScripter->GetScriptSourceBA(typeChar, &textData) )
  1607.             {
  1608.                 gGlobals->fTextTransferExt->SetData(ev, typeChar, &textData);
  1609.                 DisposeByteArrayStruct(textData);
  1610.             }
  1611.         }
  1612.     SOM_CATCH_ALL
  1613.     SOM_ENDTRY
  1614. }
  1615.  
  1616. //------------------------------------------------------------------------------
  1617. // Method:        MovePalette
  1618. // Origin:        ScriptRunner
  1619. //
  1620. // Description:    This method is called by the palette extension to
  1621. //                position the palette window to the point passed in.
  1622. //------------------------------------------------------------------------------
  1623. SOM_Scope    ODBoolean
  1624. SOMLINK        ScriptRunner__MovePalette
  1625.              (
  1626.                 SampleCode_ScriptRunner*        somSelf,
  1627.                 Environment*                    ev,
  1628.                 ODPoint*                        point
  1629.             )
  1630. {
  1631.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","MovePalette");
  1632.  
  1633.     ODBoolean    result = kODFalse;
  1634.     ODSShort    left = point->x;
  1635.     ODSShort    top = point->y;
  1636.  
  1637.     ODWindow* window = somSelf->AcquireWindowByID(ev, gGlobals->fPaletteID);
  1638.     if ( window )
  1639.     {
  1640.         SetRect(&gGlobals->fPaletteBounds, left, top, left+kPaletteWidth, top+kPaletteHeight);
  1641.         MoveWindow((WindowPtr)window, left, top, kODFalse);
  1642.         ODReleaseObject(ev, window);
  1643.         result = kODTrue;
  1644.     }
  1645.  
  1646.     return result;
  1647. }
  1648.  
  1649. //------------------------------------------------------------------------------
  1650. // Method:        GetPaletteLocation
  1651. // Origin:        ScriptRunner
  1652. //
  1653. // Description:    Returns the top left corner of the palette window.
  1654. //------------------------------------------------------------------------------
  1655. SOM_Scope ODPoint*
  1656. SOMLINK ScriptRunner__GetPaletteLocation(SampleCode_ScriptRunner *somSelf, Environment *ev)
  1657. {
  1658.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","GetPaletteLocation");
  1659.     
  1660.     ODPoint* pt = kODNULL;
  1661.     
  1662.     ODVolatile(pt);
  1663.     
  1664.     SOM_TRY
  1665.         // Allocate and set the point coordinates.
  1666.         pt = new ODPoint;
  1667.         pt->x = gGlobals->fPaletteBounds.left;
  1668.         pt->y = gGlobals->fPaletteBounds.top;
  1669.     SOM_CATCH_ALL
  1670.     SOM_ENDTRY
  1671.  
  1672.     return pt;
  1673. }
  1674.  
  1675. //------------------------------------------------------------------------------
  1676. // Method:        LoadPalette
  1677. // Origin:        ScriptRunner
  1678. //
  1679. // Description:    This method is called by the part to load its control palette.
  1680. //------------------------------------------------------------------------------
  1681. SOM_Scope    void
  1682. SOMLINK        ScriptRunner__LoadPalette
  1683.              (
  1684.                 SampleCode_ScriptRunner*        somSelf,
  1685.                 Environment*                    ev
  1686.             )
  1687. {
  1688.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","LoadPalette");
  1689.  
  1690.     SOM_TRY
  1691.         ODSLong savedRef = BeginUsingLibraryResources();
  1692.         {
  1693.             gGlobals->fPalette = (Handle)GetPicture(kControlsID);
  1694.             DetachResource(gGlobals->fPalette);
  1695.         }
  1696.         EndUsingLibraryResources(savedRef);
  1697.         
  1698.         // If we were unable to load the PICT resource for whatever reason,
  1699.         // we will throw the Resource Manager error as an exception.
  1700.     
  1701.         if ( gGlobals->fPalette == kODNULL )
  1702.         {
  1703.             // There is a bug in ResError, when resources are not found,
  1704.             // which may cause noErr to be returned. If that is the case,
  1705.             // we throw resNotFound.
  1706.             THROW_IF_ERROR((ODError)ResError());
  1707.             THROW(resNotFound);
  1708.     }
  1709.     SOM_CATCH_ALL
  1710.     SOM_ENDTRY
  1711. }
  1712.  
  1713. //------------------------------------------------------------------------------
  1714. // Method:        IsPaletteVisible
  1715. // Origin:        ScriptRunner
  1716. //------------------------------------------------------------------------------
  1717. SOM_Scope    ODBoolean
  1718. SOMLINK        ScriptRunner__IsPaletteVisible
  1719.             (
  1720.                 SampleCode_ScriptRunner*        somSelf,
  1721.                 Environment*                    ev
  1722.             )
  1723. {
  1724.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner", "IsPaletteVisible");
  1725.     
  1726.     return gGlobals->fPaletteVisible;
  1727. }
  1728.  
  1729. //------------------------------------------------------------------------------
  1730. // Method:        ShowPalette
  1731. // Origin:        ScriptRunner
  1732. //
  1733. // Description:    This method is called by the palette extension to show
  1734. //                the scripting palette.
  1735. //------------------------------------------------------------------------------
  1736. SOM_Scope    void
  1737. SOMLINK        ScriptRunner__ShowPalette
  1738.              (
  1739.                  SampleCode_ScriptRunner*        somSelf,
  1740.                  Environment*                    ev
  1741.              )
  1742. {
  1743.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","ShowPalette");
  1744.     
  1745.     SOM_TRY
  1746.         if ( !gGlobals->fPaletteVisible )
  1747.         {
  1748.             TempODWindow window = somSelf->AcquireWindowByID(ev, gGlobals->fPaletteID);
  1749.             THROW_IF_NULL(window);
  1750.             
  1751.             // Make the window visible.
  1752.             window->Show(ev);
  1753.             gGlobals->fPaletteVisible = kODTrue;
  1754.             
  1755.             if ( gGlobals->fResultHidden )
  1756.             {
  1757.                 somSelf->DisplayResult(ev);
  1758.                 gGlobals->fResultHidden = kODFalse;
  1759.             }
  1760.         }
  1761.     SOM_CATCH_ALL
  1762.     SOM_ENDTRY
  1763. }
  1764.  
  1765. //------------------------------------------------------------------------------
  1766. // Method:        HidePalette
  1767. // Origin:        ScriptRunner
  1768. //------------------------------------------------------------------------------
  1769. SOM_Scope    void
  1770. SOMLINK        ScriptRunner__HidePalette
  1771.              (
  1772.                  SampleCode_ScriptRunner*        somSelf,
  1773.                  Environment*                    ev
  1774.              )
  1775. {
  1776.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner", "HidePalette");
  1777.  
  1778.     SOM_TRY
  1779.         if ( gGlobals->fPaletteVisible )
  1780.         {
  1781.             TempODWindow window = somSelf->AcquireWindowByID(ev, gGlobals->fPaletteID);        
  1782.             // If we don't have a window, then something is wrong
  1783.             THROW_IF_NULL(window);
  1784.  
  1785.             // Hide the palette window.
  1786.             window->Hide(ev);
  1787.             gGlobals->fPaletteVisible = kODFalse;
  1788.             
  1789.             if ( gGlobals->fResultWindowVisible )
  1790.             {
  1791.                 // Also hide the Result window and set its flag.
  1792.                 somSelf->HideResultWindow(ev);
  1793.                 gGlobals->fResultHidden = kODTrue;
  1794.             }
  1795.         }
  1796.     SOM_CATCH_ALL
  1797.     SOM_ENDTRY
  1798. }
  1799.  
  1800. //------------------------------------------------------------------------------
  1801. // Method:        IsResultWindowVisible
  1802. // Origin:        ScriptRunner
  1803. //------------------------------------------------------------------------------
  1804. SOM_Scope    ODBoolean
  1805. SOMLINK        ScriptRunner__IsResultWindowVisible
  1806.             (
  1807.                 SampleCode_ScriptRunner*        somSelf,
  1808.                 Environment*                    ev
  1809.             )
  1810. {
  1811.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner", "IsResultWindowVisible");
  1812.     
  1813.     return gGlobals->fResultWindowVisible;
  1814. }
  1815.  
  1816. //------------------------------------------------------------------------------
  1817. // Method:        CreateResultWindow
  1818. // Origin:        ScriptRunner
  1819. //
  1820. // Description:    This method is called by the palette extension to show
  1821. //                the scripting palette.
  1822. //------------------------------------------------------------------------------
  1823. SOM_Scope    ODWindow*
  1824. SOMLINK        ScriptRunner__CreateResultWindow
  1825.              (
  1826.                  SampleCode_ScriptRunner*    somSelf,
  1827.                  Environment*                ev
  1828.              )
  1829. {
  1830.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","CreateResultWindow");
  1831.     
  1832.     ODWindow* window;        // Released by the caller.
  1833.     
  1834.     SOM_TRY
  1835.         Str63 windowTitle;
  1836.         
  1837.         // Get the window title string from our library's resources.
  1838.         // (Note: ODGetIndString focuses the resource fork for us)
  1839.         ODGetIndString(windowTitle, kStringResID, kResultsIndex);
  1840.  
  1841.         // The Result window hasn't been created yet; create it.
  1842.         window = somSelf->CreateWindow(ev, gGlobals->fResultPresentation,
  1843.                                     floatGrowProc, windowTitle, &gGlobals->fResultBounds);
  1844.         THROW_IF_NULL(window);
  1845.  
  1846.         // Create the facet hierarchy for this window.
  1847.         window->Open(ev);
  1848.         gGlobals->fResultID = window->GetID(ev);
  1849.     SOM_CATCH_ALL
  1850.     SOM_ENDTRY
  1851.     
  1852.     return window;
  1853. }
  1854.  
  1855. //------------------------------------------------------------------------------
  1856. // Method:        ShowResultWindow
  1857. // Origin:        ScriptRunner
  1858. //------------------------------------------------------------------------------
  1859. SOM_Scope    ODWindow*
  1860. SOMLINK        ScriptRunner__ShowResultWindow
  1861.              (
  1862.                  SampleCode_ScriptRunner*        somSelf,
  1863.                  Environment*                    ev
  1864.              )
  1865. {
  1866.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner", "ShowResultWindow");
  1867.     
  1868.     ODWindow*    window = kODNULL;
  1869.     
  1870.     ODVolatile(window);
  1871.     
  1872.     SOM_TRY
  1873.         if ( gGlobals->fResultID == kODNULLID )
  1874.             window = somSelf->CreateResultWindow(ev);
  1875.         else
  1876.             window = somSelf->AcquireWindowByID(ev, gGlobals->fResultID);
  1877.  
  1878.         THROW_IF_NULL(window);
  1879.         
  1880.         if ( !gGlobals->fResultWindowVisible )
  1881.         {
  1882.             // Show the Result window.
  1883.             window->Show(ev);
  1884.             gGlobals->fResultWindowVisible = kODTrue;
  1885.         }
  1886.     SOM_CATCH_ALL
  1887.     SOM_ENDTRY
  1888.     
  1889.     return window;
  1890. }
  1891.  
  1892. //------------------------------------------------------------------------------
  1893. // Method:        HideResultWindow
  1894. // Origin:        ScriptRunner
  1895. //------------------------------------------------------------------------------
  1896. SOM_Scope    void
  1897. SOMLINK        ScriptRunner__HideResultWindow
  1898.              (
  1899.                  SampleCode_ScriptRunner*        somSelf,
  1900.                  Environment*                    ev
  1901.              )
  1902. {
  1903.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner", "HideResultWindow");
  1904.     
  1905.     SOM_TRY
  1906.         if ( gGlobals->fResultWindowVisible )
  1907.         {
  1908.             TempODWindow window = somSelf->AcquireWindowByID(ev, gGlobals->fResultID);
  1909.             // If we don't have a window, then something is wrong
  1910.             THROW_IF_NULL(window);
  1911.  
  1912.             // Hide the Result window.
  1913.             window->Hide(ev);
  1914.             gGlobals->fResultWindowVisible = kODFalse;
  1915.         }
  1916.     SOM_CATCH_ALL
  1917.     SOM_ENDTRY
  1918. }
  1919.  
  1920. //------------------------------------------------------------------------------
  1921. // Method:        DisplayResult
  1922. // Origin:        ScriptRunner
  1923. //
  1924. // Description: This method displays the result after script execution.
  1925. //------------------------------------------------------------------------------
  1926. SOM_Scope    void
  1927. SOMLINK        ScriptRunner__DisplayResult
  1928.              (
  1929.                 SampleCode_ScriptRunner*        somSelf,
  1930.                 Environment*                    ev
  1931.             )
  1932. {
  1933.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","DisplayResult");
  1934.     
  1935.     GrafPtr        thePort;
  1936.     Rect         bounds;
  1937.     
  1938.     SOM_TRY
  1939.         TempODWindow window = somSelf->ShowResultWindow(ev);
  1940.         THROW_IF_NULL(window);
  1941.  
  1942.         if ( gGlobals->fResultValue == kODNULL )
  1943.         {
  1944.             gGlobals->fResultValue = gGlobals->fOSAScripter->GetResultAsText(ev);
  1945.             if ( !gGlobals->fResultValue )
  1946.             {
  1947.                 Str63 text;
  1948.                 // Get the "< no result >" string from our library's resources.
  1949.                 // (note: ODGetIndString focuses the resource fork for us)
  1950.                 ODGetIndString(text, kStringResID, kNoResultIndex);
  1951.                 
  1952.                 ODSShort length = text[0];
  1953.                 gGlobals->fResultValue = (ODISOStr) ODNewPtr(length + 1);
  1954.                 ODISOStrNCopy(gGlobals->fResultValue, (ODISOStr)text+1, length);
  1955.                 ((char*)gGlobals->fResultValue)[length] = '\0';
  1956.             }
  1957.         }
  1958.         
  1959.         ODFacet* facet = window->GetRootFacet(ev);
  1960.         // Focus the port and origin for drawing in our facet. Note that
  1961.         // this instance of the CFocus class is being allocated. When the
  1962.         // execution leaves the scope of this method, the destructor is
  1963.         // automatically called and cleans up the drawing environment.
  1964.         CFocus initiateDrawing(ev, facet);
  1965.         
  1966.         GetPort(&thePort);
  1967.         EraseRect(&thePort->portRect);
  1968.         
  1969.         TempODShape frameShape = window->GetRootFrame(ev)->AcquireFrameShape(ev, kODNULL);
  1970.  
  1971.         RgnHandle rgn = frameShape->GetQDRegion(ev);
  1972.         bounds = (**rgn).rgnBBox;
  1973.         TETextBox(gGlobals->fResultValue, ODISOStrLength(gGlobals->fResultValue), &bounds, teFlushLeft);
  1974.         window->Select(ev);
  1975.     SOM_CATCH_ALL
  1976.         if ( gGlobals->fResultValue )
  1977.         {
  1978.             ODDisposePtr(gGlobals->fResultValue);
  1979.             gGlobals->fResultValue = kODNULL;
  1980.         }
  1981.     SOM_ENDTRY
  1982. }
  1983.  
  1984. //------------------------------------------------------------------------------
  1985. // Method:        DoErrorDialog
  1986. //
  1987. // Description:    This method is called when an OSA error occurs.
  1988. //------------------------------------------------------------------------------
  1989. SOM_Scope    void
  1990. SOMLINK        ScriptRunner__DoErrorDialog
  1991.              (
  1992.                 SampleCode_ScriptRunner*        somSelf,
  1993.                 Environment*                    ev,
  1994.                 ODFrame*                        frame
  1995.             )
  1996. {
  1997.     SampleCode_ScriptRunnerData *somThis = SampleCode_ScriptRunnerGetData(somSelf);
  1998.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","DoErrorDialog");
  1999.  
  2000.     SOM_TRY
  2001.         ODSession* session = ODGetSession(ev, _fSelf);
  2002.         
  2003.         // We must request the Modal focus to prevent multiple modal
  2004.         // dialogs from being displayed simultaneously.
  2005.         
  2006.         if ( session->GetArbitrator(ev)->RequestFocus(ev,  gGlobals->fModalFocus, frame) )
  2007.         {
  2008.             DialogPtr    dialog;
  2009.             ODSShort    itemHit;
  2010.     
  2011.             // Dim the frontmost document window.
  2012.             session->GetWindowState(ev)->DeactivateFrontWindows(ev);
  2013.                     
  2014.             ODSLong savedRef;
  2015.             savedRef = BeginUsingLibraryResources();
  2016.             {            
  2017.                 dialog = GetNewDialog(kErrorBoxID, kODNULL, (WindowPtr)-1L);
  2018.                 
  2019.                 if ( dialog )
  2020.                 {
  2021.                     Handle        itemHandle;
  2022.                     Rect        itemRect;
  2023.                     short        itemType;
  2024.     
  2025.                     ODISOStr errStr = gGlobals->fOSAScripter->GetErrorMessage(ev);
  2026.                     
  2027.                     if ( errStr )
  2028.                     {
  2029.                         GetDialogItem(dialog, kErrStrFieldID, &itemType, &itemHandle, &itemRect);
  2030.                         TempODString string = (ODISOStr)CToPascalString((char*)errStr);
  2031.                         SetDialogItemText(itemHandle, (unsigned const char*)errStr);
  2032.     
  2033.                         SetCursor(&ODQDGlobals.arrow);
  2034.                         ModalDialog(kODNULL, &itemHit);
  2035.                     }
  2036.                     DisposeDialog(dialog);
  2037.                 }
  2038.                 else
  2039.                 {
  2040.                     // Could not load error box dialog... something is wrong.
  2041.                     SysBeep(2);
  2042.                 }
  2043.             }
  2044.             EndUsingLibraryResources(savedRef);
  2045.             
  2046.             // Inform the Arbitrator that we no longer require the Modal focus.
  2047.             session->GetArbitrator(ev)->RelinquishFocus(ev,  gGlobals->fModalFocus, frame);
  2048.             
  2049.             // Hilite the frontmost document window.
  2050.             session->GetWindowState(ev)->ActivateFrontWindows(ev);
  2051.         }
  2052.         else
  2053.             // If we can't get the modal focus, then another modal dialog is
  2054.             // already being displayed.
  2055.             SysBeep(2);
  2056.     SOM_CATCH_ALL
  2057.     SOM_ENDTRY
  2058. }
  2059.  
  2060. //------------------------------------------------------------------------------
  2061. // Method:        GeometryChanged
  2062. //
  2063. // Description:    This method is called when the ExternalTransform or
  2064. //                ClipShape of a facet on one of this part's display
  2065. //                frames changes.
  2066. //------------------------------------------------------------------------------
  2067. SOM_Scope     void
  2068. SOMLINK        ScriptRunner__GeometryChanged
  2069.         (
  2070.             SampleCode_ScriptRunner*        somSelf, 
  2071.             Environment*                    ev,
  2072.             ODFacet*                         facet,
  2073.             ODBoolean                        clipShapeChanged,
  2074.             ODBoolean                        externalTransformChanged
  2075.         )
  2076. {
  2077.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","GeometryChanged");
  2078.  
  2079.     if ( clipShapeChanged )
  2080.         // Specifying kODNULL means to invalidate the clipShape (which was
  2081.         // calculated from the usedShape).
  2082.         facet->Invalidate(ev, kODNULL, kODNULL);
  2083. }
  2084.  
  2085. //------------------------------------------------------------------------------
  2086. // Method:        InitiateDrag
  2087. // Origin:        ScriptRunner
  2088. //
  2089. // Description:    Begin the drag transaction on the Result.
  2090. //------------------------------------------------------------------------------
  2091. SOM_Scope     ODDropResult
  2092. SOMLINK        ScriptRunner__InitiateDrag
  2093.         (
  2094.             SampleCode_ScriptRunner*        somSelf,
  2095.             Environment*                    ev,
  2096.             ODEventData*                    event, 
  2097.             ODFacet*                        facet, 
  2098.             ODPoint*                        where
  2099.         )
  2100. {
  2101.     SampleCode_ScriptRunnerData *somThis = SampleCode_ScriptRunnerGetData(somSelf);
  2102.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","InitiateDrag");
  2103.     
  2104.     ODDropResult dropResult = kODDropFail;
  2105.  
  2106.     SOM_TRY        
  2107.         ODFrame* frame = facet->GetFrame(ev);
  2108.     
  2109.         // Get the ODDragAndDrop object from the session.
  2110.         ODDragAndDrop* dragNdrop = ODGetSession(ev, _fSelf)->GetDragAndDrop(ev);
  2111.         
  2112.         // Reinitialize the ODDragAndDrop object.
  2113.         dragNdrop->Clear(ev);
  2114.         
  2115.         // Get the Storage Unit where data for dragged objects are going to be written.
  2116.         ODStorageUnit* contentSU = dragNdrop->GetContentStorageUnit(ev);
  2117.         
  2118.         // Write out the text data into the content property.
  2119.         // Note: ODSetISOStrProp will add the property and value to the 
  2120.         // storage unit if it doesn't exist. Otherwise, it will set the
  2121.         // focus appropriately.
  2122.         ODSetISOStrProp(ev, contentSU, kODPropContents, gGlobals->fTextKind, 
  2123.                             gGlobals->fResultValue);
  2124.     
  2125.         // Annotate the content storage unit with the frame shape.
  2126.         TempODShape frameShape = frame->AcquireFrameShape(ev, kODNULL);
  2127.         contentSU->AddProperty(ev, kODPropSuggestedFrameShape);
  2128.         frameShape->WriteShape(ev, contentSU);
  2129.     
  2130.         // Write out the mouse down offset.
  2131.         ODSetPointProp(ev, contentSU, kODPropMouseDownOffset, kODPoint, where);
  2132.         
  2133.         // Initiate the drag.
  2134.         TempODPart tempDestPart = kODNULL;
  2135.         
  2136.         // Get the drag region.
  2137.         ODRgnHandle dragRgn = somSelf->CreateDragRegion(ev, facet);
  2138.     
  2139.         TRY
  2140.             // Create byte arrays for dragRgn and refCon (which is the event record).
  2141.             TempODByteArray dragRgnBA = CreateByteArray(&dragRgn, sizeof(RgnHandle));
  2142.             TempODByteArray eventBA   = CreateByteArray(&event, sizeof(ODEventData*));    // event is of type ODEventData*.
  2143.             
  2144.             ODPart* destPart = kODNULL;
  2145.             dropResult = dragNdrop->StartDrag(ev, facet->GetFrame(ev), 
  2146.                                                 kODDragImageRegionHandle, 
  2147.                                                 dragRgnBA, &destPart, eventBA);
  2148.             // Assign the temp pointer to destPart so it will be
  2149.             // released automatically.
  2150.             tempDestPart = destPart;
  2151.         CATCH_ALL
  2152.             DisposeRgn(dragRgn);
  2153.             RERAISE;
  2154.         ENDTRY
  2155.         
  2156.         DisposeRgn(dragRgn);
  2157.         
  2158.         // We don't handle the dropResult since we only allow a copy.
  2159.     SOM_CATCH_ALL
  2160.     SOM_ENDTRY
  2161.  
  2162.     return dropResult;
  2163. }
  2164.  
  2165. //------------------------------------------------------------------------------
  2166. // Method:        CreateDragRegion
  2167. // Origin:        ScriptRunner
  2168. //------------------------------------------------------------------------------
  2169. SOM_Scope     ODRgnHandle
  2170. SOMLINK        ScriptRunner__CreateDragRegion
  2171.         (
  2172.             SampleCode_ScriptRunner*        somSelf,
  2173.             Environment*                    ev,
  2174.            ODFacet*                            facet
  2175.         )
  2176. {
  2177.     SampleCode_ScriptRunnerData *somThis = SampleCode_ScriptRunnerGetData(somSelf);
  2178.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","CreateDragRegion");
  2179.  
  2180.     ODRgnHandle dragRgn = ODNewRgn();
  2181.  
  2182.     SOM_TRY
  2183.         TempODShape frameShape = facet->GetFrame(ev)->AcquireFrameShape(ev, kODNULL);
  2184.         
  2185.         CopyRgn(frameShape->GetQDRegion(ev), dragRgn);
  2186.     
  2187.         // Inset the region and subtract it from the original.
  2188.         {
  2189.             ODRgnHandle insetRgn = ODNewRgn();
  2190.             
  2191.             CopyRgn(dragRgn, insetRgn);
  2192.             InsetRgn(insetRgn, 1, 1);
  2193.             DiffRgn(dragRgn, insetRgn, dragRgn);
  2194.     
  2195.             ODDisposeHandle((ODHandle)insetRgn);
  2196.         }
  2197.         
  2198.         // Put the region in global coordinates.
  2199.         {
  2200.             CFocus forMapping(ev, facet);
  2201.             
  2202.             Point localToGlobalTrans = { 0, 0 };
  2203.             LocalToGlobal(&localToGlobalTrans);
  2204.             OffsetRgn(dragRgn, localToGlobalTrans.h, localToGlobalTrans.v);
  2205.         }
  2206.     SOM_CATCH_ALL
  2207.         ODDisposeHandle((ODHandle)dragRgn);
  2208.         dragRgn = kODNULL;
  2209.     SOM_ENDTRY
  2210.     
  2211.     return dragRgn;
  2212. }
  2213.  
  2214. //=======================================================================
  2215. //
  2216. // Unimplemented Methods • Unimplemented Methods • Unimplemented Methods
  2217. //
  2218. //=======================================================================
  2219.  
  2220. //------------------------------------------------------------------------------
  2221. // Method:        ReadPartInfo
  2222. // Origin:        ODPart
  2223. //------------------------------------------------------------------------------
  2224. SOM_Scope    ODInfoType
  2225. SOMLINK        ScriptRunner__ReadPartInfo( SampleCode_ScriptRunner* somSelf,
  2226.                 Environment* ev, ODFrame* frame, ODStorageUnitView* storageUnitView )
  2227. {
  2228.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","ReadPartInfo");
  2229.  
  2230.     return kODNULL;
  2231. }
  2232.  
  2233. //------------------------------------------------------------------------------
  2234. // Method:        WritePartInfo
  2235. // Origin:        ODPart
  2236. //
  2237. // Description:    When a frame is being externalized by the Draft, it will ask the
  2238. //                owner (part) to write out its info annotation on the frame.
  2239. //------------------------------------------------------------------------------
  2240. SOM_Scope    void
  2241. SOMLINK        ScriptRunner__WritePartInfo( SampleCode_ScriptRunner* somSelf,
  2242.                 Environment* ev, ODInfoType partInfo, ODStorageUnitView* storageUnitView )
  2243. {
  2244.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","WritePartInfo");
  2245. }
  2246.  
  2247. //------------------------------------------------------------------------------
  2248. // Method:        ClonePartInfo
  2249. // Origin:        ODPart
  2250. //
  2251. // Description:    When a frame is being cloned by the Draft, it will ask the owner
  2252. //                (part) to clone its info annotation on the frame.
  2253. //------------------------------------------------------------------------------
  2254. SOM_Scope    void
  2255. SOMLINK        ScriptRunner__ClonePartInfo( SampleCode_ScriptRunner* somSelf,
  2256.                 Environment* ev, ODDraftKey key, ODInfoType partInfo, 
  2257.                 ODStorageUnitView* storageUnitView, ODFrame* scopeFrame )
  2258. {
  2259.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","ClonePartInfo");
  2260. }
  2261.  
  2262. //------------------------------------------------------------------------------
  2263. // Method:        ContainingPartPropertiesUpdated
  2264. // Origin:        ODPart
  2265. //------------------------------------------------------------------------------
  2266. SOM_Scope    void
  2267. SOMLINK        ScriptRunner__ContainingPartPropertiesUpdated(SampleCode_ScriptRunner *somSelf,
  2268.                                     Environment *ev, ODFrame* /*frame*/, ODStorageUnit* /*propertyUnit*/)
  2269. {
  2270.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","ContainingPartPropertiesUpdated");
  2271. }
  2272.  
  2273. //------------------------------------------------------------------------------
  2274. // Method:        FrameShapeChanged
  2275. // Origin:        ODPart
  2276. //
  2277. // Description:    This method is called in response to a frame's shape being
  2278. //                altered, either by the user or the part we are embedded in.
  2279. //------------------------------------------------------------------------------
  2280. SOM_Scope    void
  2281. SOMLINK        ScriptRunner__FrameShapeChanged( SampleCode_ScriptRunner* somSelf,
  2282.                 Environment* ev, ODFrame* frame )
  2283. {
  2284.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","FrameShapeChanged");
  2285. }
  2286.  
  2287. //------------------------------------------------------------------------------
  2288. // Method:        PresentationChanged
  2289. // Origin:        ODPart
  2290. //------------------------------------------------------------------------------
  2291. SOM_Scope    void
  2292. SOMLINK        ScriptRunner__PresentationChanged(SampleCode_ScriptRunner *somSelf,
  2293.                                                 Environment *ev, ODFrame* /*frame*/)
  2294. {
  2295.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","PresentationChanged");
  2296. }
  2297.  
  2298. //------------------------------------------------------------------------------
  2299. // Method:        SequenceChanged
  2300. // Origin:        ODPart
  2301. //------------------------------------------------------------------------------
  2302. SOM_Scope    void
  2303. SOMLINK        ScriptRunner__SequenceChanged(SampleCode_ScriptRunner *somSelf,
  2304.                                         Environment *ev, ODFrame* /*frame*/)
  2305. {
  2306.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","SequenceChanged");
  2307. }
  2308.  
  2309. //------------------------------------------------------------------------------
  2310. // Method:        FacetAdded
  2311. // Origin:        ODPart
  2312. //
  2313. // Description:    This method is called when any part adds a facet to
  2314. //                one of our display frames.
  2315. //------------------------------------------------------------------------------
  2316. SOM_Scope    void
  2317. SOMLINK        ScriptRunner__FacetAdded( SampleCode_ScriptRunner* somSelf,
  2318.                     Environment* ev, ODFacet* facet )
  2319. {
  2320.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","FacetAdded");
  2321. }
  2322.  
  2323. //------------------------------------------------------------------------------
  2324. // Method:        FacetRemoved
  2325. // Origin:        ODPart
  2326. //
  2327. // Description:    This method is called when any part removes a facet from
  2328. //                one of our display frames.
  2329. //
  2330. //                The part just removes the "active" flag from the appropriate
  2331. //                display frame if necessary since this facet will not be
  2332. //                available, or active, again.
  2333. //------------------------------------------------------------------------------
  2334. SOM_Scope    void
  2335. SOMLINK        ScriptRunner__FacetRemoved( SampleCode_ScriptRunner* somSelf,
  2336.                     Environment* ev, ODFacet* facet )
  2337. {
  2338.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","FacetRemoved");
  2339. }
  2340.  
  2341. //------------------------------------------------------------------------------
  2342. // Method:        AttachSourceFrame
  2343. // Origin:        ODPart
  2344. //
  2345. // Description:    If a part which we are contained in is opened into a part
  2346. //                window, it is required to iterate over its embedded frames and
  2347. //                add new display frames in the part window. After each new
  2348. //                embedded frame is created, this method will be called.
  2349. //------------------------------------------------------------------------------
  2350. SOM_Scope    void
  2351. SOMLINK        ScriptRunner__AttachSourceFrame( SampleCode_ScriptRunner* somSelf,
  2352.                 Environment* ev, ODFrame* frame, ODFrame* sourceFrame )
  2353. {
  2354.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","AttachSourceFrame");
  2355. }
  2356.  
  2357.  
  2358. //------------------------------------------------------------------------------
  2359. // Method:        AdjustMenus
  2360. // Origin:        ODPart
  2361. //
  2362. // Description:    This method is called when a kODEvtMouseDown event
  2363. //                occurs in the menubar and the part owns the menu
  2364. //                focus. The part enables the appropriate items for its current
  2365. //                state and updates the menu items.
  2366. //------------------------------------------------------------------------------
  2367. SOM_Scope    void
  2368. SOMLINK        ScriptRunner__AdjustMenus( SampleCode_ScriptRunner* somSelf,
  2369.                     Environment* ev, ODFrame* frame ) 
  2370. {
  2371.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","AdjustMenus");
  2372. }
  2373.  
  2374. //------------------------------------------------------------------------------
  2375. // Method:        CanvasChanged
  2376. // Origin:        ODPart
  2377. //------------------------------------------------------------------------------
  2378. SOM_Scope    void
  2379. SOMLINK        ScriptRunner__CanvasChanged(SampleCode_ScriptRunner* somSelf,
  2380.                                             Environment* ev, ODFacet* /*facet*/)
  2381. {
  2382.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","CanvasChanged");
  2383. }
  2384.  
  2385. //------------------------------------------------------------------------------
  2386. // Method:        CanvasUpdated
  2387. // Origin:        ODPart
  2388. //------------------------------------------------------------------------------
  2389. SOM_Scope    void
  2390. SOMLINK        ScriptRunner__CanvasUpdated(SampleCode_ScriptRunner *somSelf, Environment *ev,
  2391.                                 ODCanvas* /*canvas*/)
  2392. {
  2393.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","CanvasUpdated");
  2394. }
  2395.  
  2396. //------------------------------------------------------------------------------
  2397. // Method:        HighlightChanged
  2398. // Origin:        ODPart
  2399. //------------------------------------------------------------------------------
  2400. SOM_Scope    void
  2401. SOMLINK        ScriptRunner__HighlightChanged(SampleCode_ScriptRunner*    somSelf,
  2402.                                             Environment* ev, ODFacet* /*facet*/)
  2403. {
  2404.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","HighlightChanged");
  2405. }
  2406.  
  2407. //------------------------------------------------------------------------------
  2408. // Method:        GetPrintResolution
  2409. // Origin:        ODPart
  2410. //------------------------------------------------------------------------------
  2411. SOM_Scope    ODULong
  2412. SOMLINK        ScriptRunner__GetPrintResolution(SampleCode_ScriptRunner *somSelf,
  2413.                                                 Environment *ev, ODFrame* /*frame*/)
  2414. {
  2415.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","GetPrintResolution");
  2416.     return 72;
  2417. }
  2418.  
  2419. //------------------------------------------------------------------------------
  2420. // Method:        LinkStatusChanged
  2421. // Origin:        ODPart
  2422. //------------------------------------------------------------------------------
  2423. SOM_Scope    void
  2424. SOMLINK        ScriptRunner__LinkStatusChanged(SampleCode_ScriptRunner *somSelf,
  2425.                                             Environment *ev, ODFrame* /*frame*/)
  2426. {
  2427.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","LinkStatusChanged");
  2428. }
  2429.  
  2430. //------------------------------------------------------------------------------
  2431. // Method:        ExternalizeKinds
  2432. // Origin:        ODPart
  2433. //------------------------------------------------------------------------------
  2434. SOM_Scope    void
  2435. SOMLINK        ScriptRunner__ExternalizeKinds
  2436.             (
  2437.                 SampleCode_ScriptRunner*    somSelf,
  2438.                 Environment*                ev,
  2439.                 ODTypeList*                    kindset
  2440.             )
  2441. {
  2442.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","ExternalizeKinds");
  2443. }
  2444.  
  2445. //------------------------------------------------------------------------------
  2446. // Method:        ChangeKind
  2447. // Origin:        ODPart
  2448. //------------------------------------------------------------------------------
  2449. SOM_Scope    void
  2450. SOMLINK        ScriptRunner__ChangeKind
  2451.             (
  2452.                 SampleCode_ScriptRunner*        somSelf,
  2453.                 Environment*                    ev,
  2454.                 ODType                             kind
  2455.             )
  2456. {
  2457.     SampleCode_ScriptRunnerMethodDebug("ScriptRunner","ChangeKind");
  2458. }
  2459.